

#include "CppUTest/TestHarness.h"


extern "C"
{
	#include "LedDriver.h"
}


TEST_GROUP(LedDriver)
{
	uint16_t virtualLeds;

	void setup()
	{
		LedDriver_Create(&virtualLeds);
	}

	void teardown()
	{
		LedDriver_Destroy();
	}
};

TEST(LedDriver, LedsAreOffAfterCreate)
{
	virtualLeds = 0xffff;
	LedDriver_Create(&virtualLeds);
	LONGS_EQUAL(0, virtualLeds);
}

TEST(LedDriver, TurnOneLedOn)
{
	LedDriver_TurnOn(1);
	LONGS_EQUAL(1, virtualLeds);
}

TEST(LedDriver, TurnMultiLedOn)
{
	LedDriver_TurnOn(15);
	LedDriver_TurnOn(2);
	LONGS_EQUAL(0x4002, virtualLeds);
}


TEST(LedDriver, TurnAllOn)
{
	LedDriver_TurnAllOn();
	LONGS_EQUAL(0xffff, virtualLeds);
}


TEST(LedDriver, TurnOneLedOff)
{
	LedDriver_TurnOn(15);
	LedDriver_TurnOn(1);
	LedDriver_TurnOff(1);

	LONGS_EQUAL(0x4000, virtualLeds);
}

TEST(LedDriver, TurnAlloff)
{
	LedDriver_TurnAllOn();
	LedDriver_TrunAllOff();

	LONGS_EQUAL(0, virtualLeds);
}


TEST(LedDriver, LedMemoryIsNotReadable)
{
	virtualLeds = 0xffff;
	LedDriver_TurnOn(8);

	LONGS_EQUAL(0x80, virtualLeds);
}


TEST(LedDriver, OutOfBoundsChangesNothing)
{
	LedDriver_TurnOn(-1);
	LedDriver_TurnOn(0);
	LedDriver_TurnOn(17);
	LedDriver_TurnOn(3141);

	LONGS_EQUAL(0, virtualLeds);
}


TEST(LedDriver, OutOfBoundsChangesNothing2)
{
	LedDriver_TurnAllOn();
	
	LedDriver_TurnOff(-1);
	LedDriver_TurnOff(0);
	LedDriver_TurnOff(17);
	LedDriver_TurnOff(3141);

	LONGS_EQUAL(0xffff, virtualLeds);
}



TEST(LedDriver, IsOn)
{
	CHECK_EQUAL(false, LedDriver_IsOn(11));
	LedDriver_TurnOn(11);
	CHECK_EQUAL(true, LedDriver_IsOn(11));
}


TEST(LedDriver, IsOnOutBoundryOff)
{	
	CHECK_EQUAL(false, LedDriver_IsOn(-1));
	CHECK_EQUAL(false, LedDriver_IsOn(3104));
}


TEST(LedDriver, IsOff)
{
	CHECK_EQUAL(true, LedDriver_IsOff(11));
	LedDriver_TurnOn(11);
	CHECK_EQUAL(false, LedDriver_IsOff(11))
}


TEST(LedDriver, IsOffOutBoundaryOff)
{
	CHECK_EQUAL(true, LedDriver_IsOff(-1));
	CHECK_EQUAL(true, LedDriver_IsOff(3104));
}

